<template>
  <div class="video-effect" @mouseenter="ShowEffect" @mouseleave="HideEffect">
    <div class="video-slider" v-if="showDanmu">
      <el-progress :percentage="getPercent" :stroke-width="2" :color="'#fff'" :show-text="false"></el-progress>
    </div>
    <el-image :src="calImg"></el-image>
    <i class="el-icon-video-play video-hover">
      <span class="txt-tips">稍后再看</span>
    </i>
    <div class="danmu-list" v-if="showDanmu">
      <p v-for="(item,i) in danmuList" :key="i" :class="item.style">{{item.text}}</p>
    </div>
  </div>
</template>
<script>
export default {
  props: ['list'],
  data() {
    return {
      showDanmu: false,
      imgList: [
        require('../../assets/banner.png'),
        require('../../assets/icon.jpg'),
        require('../../assets/banner.png'),
        require('../../assets/icon.jpg'),
        require('../../assets/banner.png'),
        require('../../assets/icon.jpg'),
        require('../../assets/banner.png'),
        require('../../assets/icon.jpg'),
        require('../../assets/banner.png'),
        require('../../assets/icon.jpg'),
      ],
      danmuList: [
        {
          text: '我是弹幕一号111111',
          style: 'danmu-speed-fast pos-top',
        },
        {
          text: '我是弹幕二号222222',
          style: 'danmu-speed-mid pos-mid',
        },
        {
          text: '我是弹幕三号33333',
          style: 'danmu-speed-slow pos-bot',
        },
        {
          text: '我是弹幕一号111111',
          style: 'danmu-speed-fast pos-top',
        },
        {
          text: '我是弹幕二号222222',
          style: 'danmu-speed-mid pos-mid',
        },
        {
          text: '我是弹幕三号33333',
          style: 'danmu-speed-slow pos-bot',
        },
      ],
    }
  },
  computed: {
    getPercent() {
      return this.$store.state['video-percent']
    },
    calImg() {
      if (this.list === undefined) return null
      return this.list[parseInt(this.$store.state['video-percent'] % 5)]
    },
  },
  methods: {
    ShowEffect() {
      this.showDanmu = true
    },
    HideEffect() {
      this.showDanmu = false
    },
  },
}
</script>
<style scoped>
.video-effect {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: all 0.2s;
}
.video-effect:hover {
  opacity: 1;
}
.video-effect:hover .video-hover {
  opacity: 1;
}
.video-effect .el-image {
  width: 100%;
  height: 100%;
}
.video-slider {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 10px;
  background-color: #000;
  z-index: 4;
}
.video-hover {
  opacity: 0;
  position: absolute;
  display: block;
  bottom: 10px;
  right: 10px;
  color: #fff;
  width: 24px;
  height: 24px;
  background-color: rgba(0, 0, 0, 0.7);
  text-align: center;
  line-height: 24px;
  transition: all 1s;
}
.video-hover::before {
  font-size: 18px;
}
.txt-tips {
  display: block;
  position: absolute;
  top: -30px;
  left: -18px;
  width: 60px;
  border-radius: 5px;
  background-color: rgba(0, 0, 0, 0.8);
  font-size: 12px;
  transform: scale(0);
  transition: all 0.1s;
}
.video-hover:hover .txt-tips {
  transform: scale(1);
}
.danmu-list {
  position: absolute;
  top: 10px;
  left: 0;
  width: 100%;
  height: 50%;
  overflow: hidden;
}

.el-progress {
  position: absolute;
  top: 4px;
  left: 0;
  z-index: 5;
  width: 100%;
  padding: 0 5px;
}
.el-progress /deep/ .el-progress-bar__outer {
  background-color: #444444 !important;
}
.el-progress-bar__inner {
  transition: all 0.1s linear;
}
.danmu-speed-slow {
  animation: danmu 8s forwards infinite;
}
.danmu-speed-mid {
  animation: danmu 6s forwards infinite;
}
.danmu-speed-fast {
  animation: danmu 5s forwards infinite;
}
.pos-top {
  position: absolute;
  top: 0;
  right: 0;
  color: #fff;
}
.pos-mid {
  position: absolute;
  top: 10px;
  right: 0;
  color: #fff;
}
.pos-bot {
  position: absolute;
  top: 20px;
  right: 0;
  color: #fff;
}
@keyframes danmu {
  0% {
    right: 0;
    white-space: nowrap;
  }
  100% {
    right: 250px;
    white-space: nowrap;
  }
}
</style>
